/**
 * Copyright &copy; 2013-2016 山东易科德软件有限公司 All rights reserved.
 */
package cn.net.ecode.modules.cms.web;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.utils.DateUtils;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.modules.cms.service.CmsStatsService;

/**
 * 统计Controller
 * @author ThinkGem
 * @version 2014-9-16
 */
@Controller
@RequestMapping(value = "${adminPath}/cms/stats")
public class CmsStatsController extends BaseController {

	@Autowired
	private CmsStatsService cmsStatsService;
	
	/**
	 * 文章信息量
	 * @param paramMap
	 * @param model
	 */
	@RequiresPermissions("cms:stats:article")
	@RequestMapping(value = "article")
	public String article(@RequestParam Map<String, Object> paramMap, Model model) {
		// 设置默认时间范围，默认当前月
		Date beginDate = DateUtils.parseDate(paramMap.get("beginVisitTime"));
		if (beginDate == null){
			beginDate = DateUtils.setDays(new Date(), 1);
			paramMap.put("beginVisitTime", beginDate);
		}
		Date endDate = DateUtils.parseDate(paramMap.get("endVisitTime"));
		if (endDate == null){
			endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1);
			paramMap.put("endVisitTime", endDate);
		}
		model.addAllAttributes(paramMap);
		return "modules/cms/statsArticle";
	}
	
	/**
	 * 文章信息量统计数据
	 * @param paramMap
	 */
	@RequiresPermissions("cms:stats:article")
	@ResponseBody
	@RequestMapping(value = "articleData")
	public List<Map<String, Object>> articleData(@RequestParam Map<String, Object> paramMap, Model model) {
		List<Map<String, Object>> list = cmsStatsService.article(paramMap);
		return list;
	}

}
